/**
 * @Description: 高德离线地图
 * @Author: xubaoliang
 * @Date: 2022-01-25 09:19:27
 */
import TileGrid from "ol/tilegrid/TileGrid";
import TileImage from "ol/source/TileImage";
import TileLayer from "ol/layer/Tile";

let SuperMap = {
  projection: "EPSG:3857",
  initMapLayer: function () {
    let resolutions = [];
    for (let i = 0; i <= 18; i++) {
      resolutions[i] = Math.pow(2, 18 - i);
    }
    let tileGrid = new TileGrid({
      origin: [0, 0],
      resolutions: resolutions
    });
    let mapSource = new TileImage({
      projection: this.projection,
      tileGrid: tileGrid,
      tileUrlFunction: function (tileCoord) {
        if (!tileCoord) {
          return "";
        }
        let z = tileCoord[0];
        let x = tileCoord[1];
        let y = -tileCoord[2] - 1;
        if (x < 0) {
          x = "M" + (-x);
        }
        if (y < 0) {
          y = "M" + (-y);
        }
        return "http://localhost:8090/" + z + "/" + x + "/" + y + ".png";
      }
    });
    let mapLayer = new TileLayer({
      id: 'baseLayer',
      source: mapSource
    });
    return mapLayer;
  }
}

export default SuperMap;
